package com.socialbank.web.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.nybank.activity.vo.ResultMessage;
import com.nybank.fastdfs.FastDFSFile;
import com.nybank.fastdfs.FileManager;
import com.socialbank.web.bean.Promote;
import com.socialbank.web.mapper.PromoteMapper;
import com.socialbank.web.util.Numbers;
@Service
public class PromoteService {
	@Resource
	PromoteMapper mapper;
	
	
	public Object savePromote(Promote promote){
		promote.setId(Numbers.getUuidDigits19().toString());
		promote.setCreateDate(new Date());
		int count=mapper.savePromote(promote);
		return ResultMessage.success(count+"条数据插入成功", null);
	}
	public Object delPromote(Long id){
		Promote promote=mapper.findPromoteById(id);
		String fileAbsolutePath=promote.getImage();
		if(fileAbsolutePath!=null&&!fileAbsolutePath.equals("")){
			String groupName;
			String remoteFileName;
			int startIndex=fileAbsolutePath.indexOf("/",8 );
			int endIndex=fileAbsolutePath.indexOf("/",startIndex+1 );
			groupName=fileAbsolutePath.substring(startIndex+1,endIndex);
			remoteFileName=fileAbsolutePath.substring(endIndex+1);
			try {
				FileManager.deleteFile(groupName, remoteFileName);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		int count=mapper.delPromote(id);
		return ResultMessage.success(count+"条数据删除成功", null);
	}
	
	public Object findPromoteList(Long deptId){
		List<Promote> list=mapper.findPromoteList(deptId);
		return ResultMessage.success("查询成功", list);
	}
}
